package com.wangxs.cry.dec.commom;

import lombok.Data;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

@Data
public final class ServiceResult<T> implements Serializable {
    private static final long serialVersionUID = 6977558218691386450L;

    private boolean succeed = true;

    private Integer code = -1;

    private String msg;

    private T data;

    private Map<String, Object> additionalProperties = new HashMap();

    public ServiceResult() {
        this.code = 0;
        this.succeed = true;
    }

    public ServiceResult(T data) {
        this.code = 0;
        this.succeed = true;
        this.data = data;
    }

    public ServiceResult(boolean succeed, Integer code, String msg) {
        this.succeed = succeed;
        this.code = code;
        this.msg = msg;
    }

    public ServiceResult(boolean succeed, T data, String msg) {
        this.code = 0;
        this.succeed = succeed;
        this.data = data;
        this.msg = msg;
    }

    public ServiceResult(boolean succeed, T data, int code, String msg) {
        this.succeed = succeed;
        this.data = data;
        this.code = code;
        this.msg = msg;
    }

    public ServiceResult(boolean succeed, String msg) {
        this.code = 0;
        this.succeed = succeed;
        this.msg = msg;
    }

    public static ServiceResult success() {
        return new ServiceResult();
    }

    public static ServiceResult success(String msg, Object data) {
        return new ServiceResult(true, data, msg);
    }

    public static ServiceResult success(String msg) {
        return new ServiceResult(true, msg);
    }

    public static ServiceResult success(boolean succeed, String msg) {
        return new ServiceResult(succeed, msg);
    }

    public static ServiceResult error() {
        return new ServiceResult(false, -1, "错误");
    }

    public static ServiceResult error(String msg) {
        return new ServiceResult(false, -1, msg);
    }

    public static ServiceResult error(String msg, Object data) {
        return new ServiceResult(false, data, -1, msg);
    }

    public boolean isSucceed() {
        return this.succeed;
    }

}
